
class_name CPlayerSysMail

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal CharID_changed(old_value, new_value) 
signal SysMailID_changed(old_value, new_value) 
signal Flags_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.CharID = 0
    self.SysMailID = 0
    self.Flags = 0

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.CharID = _bufferStream.ReadInt64()
    self.SysMailID = _bufferStream.ReadInt64()
    self.Flags = _bufferStream.ReadUint16()

    self.bInited = true


func GetTableName():
    return 'PlayerSysMail'

func CopyFrom(other):
    self.CharID = other.CharID
    self.SysMailID = other.SysMailID
    self.Flags = other.Flags


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CPlayerSysMail.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CPlayerSysMail", [self, old, self])
        return true

    print("UnPackField error tblName = PlayerSysMail, className = CPlayerSysMail, _fieldId = ", _fieldId)
    # if _fieldId > Fields_PlayerSysMailID.size():
    #     var szLog = 'CPlayerSysMail.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_PlayerSysMailID(%d)' % [_fieldId, _fieldId,  Fields_PlayerSysMailID.size()]
    #     print(szLog)
    #     return false

    # Fields_PlayerSysMailID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CPlayerSysMail", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CPlayerSysMail", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var CharID:
    set(value):
        var old = self.m_CharID
        self.CharID = _value
        self.CharID_changed.emit(old, _value)

    get:
        return self.CharID


var SysMailID:
    set(value):
        var old = self.m_SysMailID
        self.SysMailID = _value
        self.SysMailID_changed.emit(old, _value)

    get:
        return self.SysMailID


var Flags:
    set(value):
        var old = self.m_Flags
        self.Flags = _value
        self.Flags_changed.emit(old, _value)

    get:
        return self.Flags



